﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using QA_System.QASysDataSetTableAdapters;
namespace QA_System
{
    public class Genre
    {
        private static GENRETableAdapter genreAdapter = new GENRETableAdapter();

        public static QASysDataSet.GENREDataTable GetAllGenre()
        {
            QASysDataSet.GENREDataTable genreTable = genreAdapter.GetData();
            return genreTable;    
        }

        public static Genrefield GetByGenreId(int genreId)
        {
            QASysDataSet.GENREDataTable genreTable = genreAdapter.GetDataByGenreId(genreId);
            if (genreTable.Rows.Count == 0)
                return null;
            else
            {
                Genrefield FData = new Genrefield();
                FData.Gen_ID = int.Parse(genreTable.Rows[0]["Gen_Id"].ToString());
                FData.KIND = genreTable.Rows[0]["Kind"].ToString();
                if (genreTable.Rows[0]["Description"] != null) FData.Description = genreTable.Rows[0]["Description"].ToString();
                else FData.Description = "";
                return (FData);
            }            
        }

        public static Genrefield GetByKind(string genreKind)
        {
            QASysDataSet.GENREDataTable genreTable = genreAdapter.GetDataByKind(genreKind);
            if (genreTable.Rows.Count == 0)
                return null;
            else
            {
                Genrefield FData = new Genrefield();
                FData.Gen_ID = int.Parse(genreTable.Rows[0]["Gen_Id"].ToString());
                FData.KIND = genreTable.Rows[0]["Kind"].ToString();
                if (genreTable.Rows[0]["Description"] != null) FData.Description = genreTable.Rows[0]["Description"].ToString();
                else FData.Description = "";
                return (FData);
            }            
        }

        public static string GetAllKindOfGenre()
        {
            try
            {
                QASysDataSet.GENREDataTable genreTable = genreAdapter.GetData();                
                string temp = ""; 
                if (genreTable.Rows.Count != 0)
                {
                    for (int i = 0; i < genreTable.Rows.Count; i++) temp += genreTable.Rows[i]["Kind"].ToString() + "/";
                }
                return temp;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}